tests: Port testwidgetfocus to using a motion controller
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 30 Jul 2018 11:13:24 +0000 (13:13 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 30 Jul 2018 11:14:12 +0000 (13:14 +0200)
tests/testwidgetfocus.c

index fc76ed22357a99e6d159c1fc19f9327bc6857c05..de179d4b35012b24ec52ae547eb834ad48869ec2 100644 (file)
@@ -199,24 +199,18 @@ gtk_focus_widget_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
     }
 }
 
-static gboolean
-gtk_focus_widget_event (GtkWidget *widget,
-                        GdkEvent  *event)
+static void
+motion_cb (GtkEventControllerMotion *controller,
+           gdouble                   x,
+           gdouble                   y,
+           GtkWidget                *widget)
 {
   GtkFocusWidget *self = GTK_FOCUS_WIDGET (widget);
-  double x, y;
-
-  if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
-    {
-      gdk_event_get_coords ((GdkEvent *)event, &x, &y);
 
-      self->mouse_x = x;
-      self->mouse_y = y;
+  self->mouse_x = x;
+  self->mouse_y = y;
 
-      gtk_widget_queue_draw (widget);
-    }
-
-  return GDK_EVENT_PROPAGATE;
+  gtk_widget_queue_draw (widget);
 }
 
 static void
@@ -235,6 +229,8 @@ gtk_focus_widget_finalize (GObject *object)
 static void
 gtk_focus_widget_init (GtkFocusWidget *self)
 {
+  GtkEventController *controller;
+
   gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
 
   self->child1 = gtk_button_new_with_label ("1");
@@ -248,6 +244,11 @@ gtk_focus_widget_init (GtkFocusWidget *self)
 
   self->mouse_x = G_MININT;
   self->mouse_y = G_MININT;
+
+  controller = gtk_event_controller_motion_new ();
+  g_signal_connect (controller, "motion",
+                   G_CALLBACK (motion_cb), self);
+  gtk_widget_add_controller (GTK_WIDGET (self), controller);
 }
 
 static void
@@ -261,7 +262,6 @@ gtk_focus_widget_class_init (GtkFocusWidgetClass *klass)
   widget_class->snapshot = gtk_focus_widget_snapshot;
   widget_class->measure = gtk_focus_widget_measure;
   widget_class->size_allocate = gtk_focus_widget_size_allocate;
-  widget_class->event = gtk_focus_widget_event;
 
   gtk_widget_class_set_css_name (widget_class, "focuswidget");
 }